home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7394 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.luc.edu!user
  2. From: VArase@varase.it.luc.edu (Verne Arase)
  3. Newsgroups: comp.lang.pl1,comp.lang.c
  4. Subject: Re: PL/I and C
  5. Date: Sun, 25 Feb 1996 22:09:35 -0600
  6. Organization: LUMC
  7. Message-ID: <AD568E9F96689203B@mcdiala11.it.luc.edu>
  8. References: <4gh5ru$eng@goanna.cs.rmit.EDU.AU> <312CCEB2.4AB7@corp.dialog.com>  <AD536AAB9668B76CD@mcdialb09.it.luc.edu> <TANMOY.96Feb23175827@qcd.lanl.gov>
  9. NNTP-Posting-Host: 147.126.240.111
  10.  
  11. In article <TANMOY.96Feb23175827@qcd.lanl.gov>,
  12. tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) wrote:
  13.  
  14.  >VA: Actually, this is incorrect.
  15.  >VA: 
  16.  >VA: In fact, if I recall correctly a pointer to x is implicitly an array.
  17.  >
  18.  >Could either of you provide examples of what you mean? I am lost ...
  19.  
  20. In C, a pointer to foo is practically the same as an array of foo. The only
  21. difference (I believe) is that the array reserves storage, and can't have
  22. its base address modified.
  23.  
  24. If you have
  25.  
  26.    foo *x;        /* declare a pointer to foo */
  27.    foo y[10];     /* declare an array of foo */
  28.  
  29.    x=y;           /* set x to the address of y */
  30.  
  31. then x[n] and y[n] should have the same address and value. A pointer to foo
  32. can be dereferenced as *x, and this would have a value which is a foo. A
  33. reference such as x[n] is actually equivalent to *(x+n) in C (in C when you
  34. add an integer 'n' to a pointer, it returns the address of the 'n'th
  35. element of that pointed-to type).
  36.  
  37. ---
  38. The above are my own opinions, and not those of my employer.
  39.